package com.huawei.appgallery.search.ui;

import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.search.api.ISearchActivityProtocol;
import com.huawei.appgallery.search.ui.HotWordFragmentProtocol.Request;
import com.huawei.appgallery.search.ui.widget.NormalSearchView;
import com.huawei.appgallery.search.ui.widget.NormalSearchView.b;
import com.huawei.hmf.annotation.ActivityDefine;
import o.azb;
import o.cgv;
import o.cjk;
import o.cjl;
import o.cjm;
import o.cjo;
import o.cju;
import o.cuv;
import o.cuv.d;
import o.cuv.e;
import o.cuv.f;
import o.cux;
import o.cvb;
import o.cvf;
import o.cvg;
import o.cvh;
import o.cvk;
import o.dgh;
import o.dgm;
import o.dgy;
import o.dof;
import o.epv;
import o.est;
import o.fiv;
import o.FragmentTransaction;

@ActivityDefine(alias = "Search", protocol = ISearchActivityProtocol.class)
public class BaseSearchActivity extends BaseActivity implements b, cvh {
    private String ʻॱ = "";
    private boolean ʽॱ;
    private boolean ʾ;
    private boolean ʿ = false;
    private String ˈ;
    private String ˉ = "";
    private boolean ˊˊ = false;
    private String ˊˋ;
    private NormalSearchView ˊॱ;
    private boolean ˊᐝ;
    private int ˋˊ = 0;
    private String ˋˋ = "";
    private fiv ˋॱ = fiv.ॱ(this);
    private cvf ˋᐝ;
    private Fragment ˌ;
    private View ˍ;
    private View ˎˎ;
    private boolean ˎˏ;
    private boolean ˏˏ;
    private ISearchActivityProtocol ˏॱ;
    protected long ͺ;
    private int ͺॱ;
    private AutoCompleteFragment ॱˊ;
    private String ॱˋ;
    private String ॱˎ = "";
    private String ᐝॱ;

    static {
        cvb.ˊ();
        cjl.ˋ("BaseResultAppList", SearchResultFragment.class);
        cju.ॱ("searchApp", "BaseResultAppList");
        cju.ॱ("searchContent", "BaseResultAppList");
        cju.ॱ("searchForum", "BaseResultAppList");
        cju.ॱ("searchPost", "BaseResultAppList");
        cju.ॱ("searchWish", "BaseResultAppList");
        cjl.ˋ("BaseHotSearch", HotWordFragment.class);
        cju.ॱ("hotsearch", "BaseHotSearch");
        cju.ॱ("hotsearchContent", "BaseHotSearch");
    }

    public void onCreate(Bundle bundle) {
        boolean needSearch;
        dgy.ˋ("hotsearch");
        super.onCreate(bundle);
        this.ˏॱ = (ISearchActivityProtocol) this.ˋॱ.ॱ();
        if (this.ˏॱ != null) {
            this.ʻॱ = this.ˏॱ.getTraceId();
            this.ॱˎ = this.ˏॱ.getIntentKeyword();
            this.ᐝॱ = this.ˏॱ.getIntentDetailId();
            this.ʿ = this.ˏॱ.getFromMain();
            this.ˈ = this.ˏॱ.getHintValue();
            this.ʽॱ = this.ˏॱ.getNotRequestHotWord();
            this.ʾ = this.ˏॱ.getNotRequestAuto();
            this.ˊᐝ = this.ˏॱ.isShowDefaultHint();
            this.ˊˋ = this.ˏॱ.getScheme();
            this.ˉ = this.ˏॱ.getDomainId();
            needSearch = this.ˏॱ.getNeedSearch();
            this.ˎˏ = this.ˏॱ.isForumSearch();
            this.ˏˏ = this.ˏॱ.isSearchPostOnly();
            this.ͺॱ = this.ˏॱ.getForumSectionId();
        } else {
            needSearch = false;
        }
        ᐝॱ();
        if (bundle != null) {
            this.ˋˊ = bundle.getInt("DataStatus");
            this.ॱˋ = bundle.getString("CurrentKeyWord");
            this.ᐝॱ = bundle.getString("CurrentKeywordDetailId");
            this.ॱˎ = bundle.getString("IntentKeyWord");
        }
        if (this.ˋˊ != 0) {
            ˉ();
        } else if (!needSearch || TextUtils.isEmpty(this.ॱˎ)) {
            ᐝ();
        } else {
            ॱ(this.ॱˎ, this.ᐝॱ, true, false);
        }
        this.ˎˎ = findViewById(cuv.b.ॱͺ);
        this.ˍ = findViewById(cuv.b.ﹳ);
        this.ˋᐝ = new cvf(this);
        this.ˋᐝ.ॱ();
    }

    private void ᐝॱ() {
        ʼॱ();
        setContentView(e.ˊॱ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(d.ˋ));
    }

    private void ʼॱ() {
        ActionBar actionBar = getActionBar();
        this.ˊॱ = new NormalSearchView(this);
        this.ˊॱ.setBackgroundColor(getResources().getColor(d.ˋ));
        cgv.ˋ(this, d.ˋ, d.ˋ);
        if (actionBar != null) {
            actionBar.setDisplayOptions(16);
            LayoutParams layoutParams = new LayoutParams(-1, -1);
            actionBar.setTitle("");
            actionBar.setCustomView(this.ˊॱ, layoutParams);
        }
        if (this.ˊॱ != null) {
            this.ˊॱ.setOnSearchActionBarListener(this);
            this.ˊॱ.ˎ();
            if (this.ʿ) {
                this.ˊॱ.setHomePageId(this.ʻॱ);
            } else {
                this.ˊॱ.setTraceId(this.ʻॱ);
            }
            this.ˊॱ.setForumSearch(this.ˎˏ);
            this.ˊॱ.setSearchPostOnly(this.ˏˏ);
            return;
        }
        cux.ˏ.ˎ("BaseSearchActivity", "initActionBar mActionBar is null!");
    }

    private void ˊˊ() {
        cjo hotWordFragmentProtocol = new HotWordFragmentProtocol();
        AppListFragmentRequest request = new Request();
        request.ʽ(this.ʽॱ);
        request.ˋ("hotsearch");
        request.ˎ(true);
        hotWordFragmentProtocol.ˏ(request);
        ContractFragment contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm("BaseHotSearch", hotWordFragmentProtocol));
        this.ˌ = contractFragment;
        FragmentTransaction ˊ = ˏॱ().ˊ();
        ˊ.ˏ(cuv.b.ﾞ, contractFragment, "HotwordFragmentTag");
        ˊ.ˋ();
        try {
            ˏॱ().ॱ();
        } catch (IllegalStateException e) {
            cux.ˏ.ˊ("BaseSearchActivity", e.toString());
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        if (bundle != null) {
            bundle.putInt("DataStatus", this.ˋˊ);
            bundle.putString("CurrentKeyWord", this.ॱˋ);
            bundle.putString("CurrentKeywordDetailId", this.ᐝॱ);
            bundle.putString("IntentKeyWord", this.ॱˎ);
            this.ˊˊ = true;
        }
        super.onSaveInstanceState(bundle);
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        this.ˋᐝ.ˏ(configuration);
    }

    private void ˉ() {
        switch (this.ˋˊ) {
            case 1:
                ᐝ();
                return;
            case 2:
                ˎ(this.ॱˋ);
                return;
            case 3:
                ॱ(this.ॱˋ, this.ᐝॱ, true, false);
                return;
            default:
                return;
        }
    }

    public void ॱ(String str, String str2, boolean z, boolean z2) {
        this.ˋˊ = 3;
        this.ॱˋ = str;
        String str3 = "";
        if (!(this.ˊॱ == null || this.ˊॱ.ॱ() == null)) {
            if (z2) {
                str3 = String.valueOf(this.ˊॱ.ॱ().ˋ());
            }
            this.ˊॱ.setmIsToResult(true);
            this.ˊॱ.ॱ().clearFocus();
            this.ˊॱ.ॱ().setQuery(str, true);
        }
        ॱ(str, str2, z, str3);
        if (!this.ʽॱ && !dof.ˋ(str)) {
            cvk.ॱ().ˏ(this, str.trim());
        }
    }

    public void ˏ(String str, String str2, boolean z, boolean z2, String str3) {
        this.ˋˋ = str3;
        ॱ(str, str2, z, z2);
    }

    private void ॱ(String str, String str2, boolean z, String str3) {
        SearchResultFragmentProtocol searchResultFragmentProtocol = new SearchResultFragmentProtocol();
        AppListFragmentRequest request = new SearchResultFragmentProtocol.Request();
        request.ॱˊ(str);
        request.ˋॱ(str2);
        request.ˊ(this.ʻॱ);
        request.ᐝॱ(str3);
        request.ॱˋ(this.ˉ);
        if (dof.ॱ(this.ˋˋ)) {
            request.ॱᐝ(this.ˊˋ);
        } else {
            request.ॱᐝ(this.ˋˋ);
            this.ˋˋ = "";
        }
        request.ˋ(this.ͺॱ);
        request.ʼ(this.ˏˏ);
        searchResultFragmentProtocol.ˏ(request);
        ॱ(searchResultFragmentProtocol, z);
    }

    private void ॱ(SearchResultFragmentProtocol searchResultFragmentProtocol, boolean z) {
        ContractFragment contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm("BaseResultAppList", (cjo) searchResultFragmentProtocol));
        if (!z) {
            FragmentTransaction ˊ = ˏॱ().ˊ();
            ˊ.ˏ(cuv.b.ﾞ, contractFragment, "SearchResultFragmentTag");
            ˊ.ˋ();
        } else if (contractFragment instanceof TaskFragment) {
            ((TaskFragment) contractFragment).ˋ(ˏॱ(), cuv.b.ﾞ, "SearchResultFragmentTag");
        }
        try {
            ˏॱ().ॱ();
        } catch (IllegalStateException e) {
            cux.ˏ.ˊ("BaseSearchActivity", e.toString());
        }
    }

    public void ˎ(String str) {
        Object obj;
        cvg o_cvg;
        this.ˋˊ = 2;
        this.ॱˋ = str;
        if (this.ॱˊ == null) {
            AutoCompleteFragment autoCompleteFragment = (AutoCompleteFragment) ˏॱ().findFragmentByTag("AutoCompleteFragmentTag");
            this.ॱˊ = autoCompleteFragment;
            if (autoCompleteFragment == null) {
                obj = 1;
                if (obj != null) {
                    this.ॱˊ = AutoCompleteFragment.ॱ(this.ʾ, str);
                }
                if (this.ॱˊ != null) {
                    o_cvg = (cvg) this.ॱˊ.ˊ(cvg.class);
                    if (o_cvg != null) {
                        o_cvg.ॱ(dgm.ˎ((Activity) this), str, this.ʾ, new cvg.b(this) {
                            final /* synthetic */ BaseSearchActivity ˎ;

                            {
                                this.ˎ = r1;
                            }

                            public void ˊ(TaskFragment taskFragment) {
                                if (2 == this.ˎ.ˋˊ) {
                                    FragmentTransaction ˊ = this.ˎ.ˏॱ().ˊ();
                                    ˊ.ˏ(cuv.b.ﾞ, this.ˎ.ॱˊ, "AutoCompleteFragmentTag");
                                    ˊ.ˋ();
                                    return;
                                }
                                this.ˎ.ॱˊ = null;
                            }

                            public void ˊ() {
                                this.ˎ.ᐝ();
                            }
                        });
                    }
                }
            }
        }
        obj = null;
        if (obj != null) {
            this.ॱˊ = AutoCompleteFragment.ॱ(this.ʾ, str);
        }
        if (this.ॱˊ != null) {
            o_cvg = (cvg) this.ॱˊ.ˊ(cvg.class);
            if (o_cvg != null) {
                o_cvg.ॱ(dgm.ˎ((Activity) this), str, this.ʾ, /* anonymous class already generated */);
            }
        }
    }

    public void ᐝ() {
        this.ˋˊ = 1;
        ˋ(this.ॱˎ);
    }

    public void ͺ() {
        ᐝ();
    }

    private void ˋ(String str) {
        if (!(this.ˊॱ == null || this.ˊॱ.ॱ() == null)) {
            if (!TextUtils.isEmpty(str) && !this.ˊᐝ) {
                this.ˊॱ.ॱ().setQueryHint(str);
                this.ˊॱ.setHintDetailId(this.ᐝॱ);
            } else if (TextUtils.isEmpty(this.ˈ)) {
                this.ˊॱ.ॱ().setQueryHint(getString(f.ॱᐝ));
            } else {
                this.ˊॱ.ॱ().setQueryHint(this.ˈ);
                this.ˊॱ.setHintValue(this.ˈ);
            }
        }
        if (!(this.ˌ instanceof TaskFragment) || ((HotWordFragment) this.ˌ).י() > 1) {
            ˊˊ();
            return;
        }
        ((TaskFragment) this.ˌ).ˋ(ˏॱ(), cuv.b.ﾞ, "HotwordFragmentTag");
        ˏॱ().ॱ();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        finish();
        return true;
    }

    public void onPause() {
        epv.ॱ((Context) this, findViewById(16908290));
        super.onPause();
        String str = "1001";
        if (System.currentTimeMillis() - this.ͺ >= 1000) {
            est.ˋ("1001");
        }
        if (dgm.ˏ((Activity) this)) {
            dgh.ˋ(this, getString(f.ˊ), this.ͺ);
        } else {
            dgh.ˋ(this, getString(f.ॱ), this.ͺ);
        }
    }

    public void onResume() {
        this.ˊˊ = false;
        super.onResume();
        this.ͺ = dgh.ॱ();
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.ˌ instanceof HotWordFragment) {
            ((HotWordFragment) this.ˌ).ˊʻ();
            this.ˌ = null;
        }
    }

    public void ॱˊ() {
        if (this.ˍ != null) {
            azb.ʼ(this.ˍ);
        }
        if (this.ˎˎ != null) {
            azb.ʼ(this.ˎˎ);
        }
    }
}
